package swingtest;

import java.awt.Container;
import java.awt.FlowLayout;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class J_LableFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public J_LableFrame() {
		super("Frame And Lable");
		String[] s = { "文本标签", "文字在图标的左侧", "文字在图标的下方" };
		ImageIcon[] icons = { null, new ImageIcon("sending.gif"), new ImageIcon("ic.png") };
		int[] ih = { 0, JLabel.LEFT, JLabel.CENTER };
		int[] iv = { 0, JLabel.CENTER, JLabel.BOTTOM };
		//获取当前框架的内容窗格
		Container c = getContentPane();
		//设置内容窗格的布局方式
		c.setLayout(new FlowLayout(FlowLayout.LEFT));
		for (int i = 0; i < iv.length; i++) {
			JLabel aLabel = new JLabel(s[i], icons[i], JLabel.LEFT);
			if (i > 0) {
				aLabel.setHorizontalTextPosition(ih[i]);
				aLabel.setVerticalTextPosition(iv[i]);
			}
			aLabel.setToolTipText("第" + (i + 1) + "个标签");
			c.add(aLabel);
		}
	}

	public static void main(String[] args) {
		J_LableFrame app = new J_LableFrame();
		app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		app.setSize(360, 150);
		app.setVisible(true);
	}

}
